package test;

import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import yns.time.TimeUtility;

public class testTimeUtility {

	public static void main(String[] args) {
		LocalDate localDate = LocalDate.now();
		System.out.println("localDate now: " + localDate);
		System.out.println("localDate getDayOfMonth: " + localDate.getDayOfMonth());
		System.out.println("localDate getDayOfYear: " + localDate.getDayOfYear());
		System.out.println("localDate getMonthValue: " + localDate.getMonthValue());
		System.out.println("localDate getMonth: " + localDate.getMonth());
		System.out.println("localDate getYear: " + localDate.getYear());
		System.out.println("localDate lengthOfMonth: " + localDate.lengthOfMonth());
		System.out.println("localDate lengthOfYear: " + localDate.lengthOfYear());
		System.out.println("localDate getDayOfWeek: " + localDate.getDayOfWeek());
		System.out.println("localDate getChronology: " + localDate.getChronology());

		System.out.println();

		LocalTime localTime = LocalTime.now();
		System.out.println("LocalTime now: " + localTime);
		System.out.println("LocalTime getHour: " + localTime.getHour());
		System.out.println("LocalTime getMinute: " + localTime.getMinute());
		System.out.println("LocalTime getSecond: " + localTime.getSecond());
		System.out.println("LocalTime getNano: " + localTime.getNano());

		System.out.println();

		LocalDateTime localDateTime = LocalDateTime.now();
		System.out.println("LocalDateTime now: " + localDateTime);
		System.out.println("LocalDateTime getDayOfMonth: " + localDateTime.getDayOfMonth());
		System.out.println("LocalDateTime getDayOfYear: " + localDateTime.getDayOfYear());
		System.out.println("LocalDateTime getMonthValue: " + localDateTime.getMonthValue());
		System.out.println("LocalDateTime getMonth: " + localDateTime.getMonth().name());
		System.out.println("LocalDateTime getYear: " + localDateTime.getYear());
		System.out.println("LocalDateTime getDayOfWeek: " + localDateTime.getDayOfWeek().name());
		System.out.println("LocalDateTime getChronology: " + localDateTime.getChronology());
		System.out.println("LocalDateTime getHour: " + localDateTime.getHour());
		System.out.println("LocalDateTime getMinute: " + localDateTime.getMinute());
		System.out.println("LocalDateTime getSecond: " + localDateTime.getSecond());
		System.out.println("LocalDateTime getNano: " + localDateTime.getNano());
		
		DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern(TimeUtility.FORMATTER_STANDARD);
		DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern(TimeUtility.FORMATTER_LONG);
		DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ofPattern(TimeUtility.FORMATTER_SHORT);

		System.out.println("Default : " + localDateTime);
		System.out.println("Formatter1 : " + localDateTime.format(dateTimeFormatter1));
		System.out.println("Formatter2 : " + localDateTime.format(dateTimeFormatter2));
		System.out.println("Formatter3 : " + localDateTime.format(dateTimeFormatter3));

		System.out.println();
		
		ZoneId defaultZone = ZoneId.systemDefault();
		System.out.println("defaultZone : " + defaultZone);
		 
		Instant instant = localDateTime.atZone(defaultZone).toInstant();
		System.out.println("localDateTime to long : " + instant.toEpochMilli());

		ZoneId zoneId = ZoneId.of(ZoneId.SHORT_IDS.get("CTT"));
		System.out.println("defaultZone : " + Instant.now().atZone(zoneId));

		long time = System.currentTimeMillis();
		System.out.println("System.currentTimeMillis() : " + time);
		System.out.println("System.currentTimeMillis defaultZone : " + Instant.ofEpochMilli(time).atZone(zoneId));
		
		System.out.println();
		
		LocalDate startDateInclusive  = LocalDate.of(2018, 11, 12);
		LocalDate endDateExclusive  = LocalDate.of(2018, 11, 24);
		Period period = Period.between(startDateInclusive, endDateExclusive);
		System.out.println("period : " + period.getDays());
		
		System.out.println("---------------------------------------");
		
		System.out.println("TimeUtility.getCurrentTime() : " + TimeUtility.getCurrentTime());
		System.out.println("TimeUtility.getCurrentLongTime() : " + TimeUtility.getCurrentLongTime());
		System.out.println("TimeUtility.getLocalDateTimeToString() : " + TimeUtility.getLocalDateTimeToString(localDateTime,null));
		System.out.println("TimeUtility.getLocalDateTimeToLong() : " + TimeUtility.getLocalDateTimeToLong(localDateTime,zoneId));
		System.out.println("TimeUtility.getStringToLocalDateTime() : " + TimeUtility.getStringToLocalDateTime(null,null));
		System.out.println("TimeUtility.getLongToLocalDateTime() : " + TimeUtility.getLongToLocalDateTime(1542440054989l));
		System.out.println("TimeUtility.getLongToString() : " + TimeUtility.getLongToString(1542440054989l,null));
		System.out.println("TimeUtility.getCurrentTimeInfo() : " + TimeUtility.getCurrentTimeInfo());
		System.out.println("TimeUtility.getCustomTimeInfo() : " + TimeUtility.getCustomTimeInfo(LocalDateTime.of(2000, 1, 3, 12, 12, 11)));
		System.out.println("TimeUtility.getFirstAndLastDateTime() : " + TimeUtility.getFirstAndLastDateTime(localDateTime));
		System.out.println("TimeUtility.getFirstAndLastDate() : " + TimeUtility.getFirstAndLastDate(localDate));
		
		int day = 18;
		LocalDate testDate = LocalDate.of(2018, 11, day);
		LocalDateTime testDateTime = LocalDateTime.of(2018, 11, day, 0, 0, 0);
		System.out.println("TimeUtility.getWeekDateTime() : " + TimeUtility.getWeekDateTime(testDateTime,DayOfWeek.MONDAY,DayOfWeek.FRIDAY));
		System.out.println("TimeUtility.getWeekDate() : " + TimeUtility.getWeekDate(testDate,DayOfWeek.SUNDAY,DayOfWeek.SATURDAY));
	}
}
